package com.xiaolin.designmode.mediator;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName ConcreteMediator
 * @Description 具体中介者
 * @Detail detail
 * @Author MyPC
 * @Date 2020/11/7
 * @Version 1.0
 */
public class ConcreteMediator implements Mediator {

    private List<Colleague> colleagues=new ArrayList<>();

    /**
     * 注册同事
     * @param colleague
     */
    @Override
    public void register(Colleague colleague) {
        if(!colleagues.contains(colleague)){
            colleagues.add(colleague);
            colleague.setMediator(this);
        }
    }

    /**
     * 转发同事信息发生了变化
     * @param colleague
     */
    @Override
    public void relay(Colleague colleague) {
        for (Colleague c : colleagues) {
            if(c != colleague){
                c.receive();
            }
        }
    }
}
